﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics.Contracts;
using System.Linq;
using System.Text;

namespace EnumUtils.Extensions
{
  public static class BitArrayExtensions
  {
    /// <summary>
    /// Provides a generic enumerable for a BitArray
    /// </summary>
    /// <param name="bitArrayToEnumerate"></param>
    /// <returns></returns>
    /// <remarks>
    /// This method only returns an IEnuerable&lt;bool&gt; because a 
    /// BitArray can only hold elements of type bool.
    /// </remarks>
    /// <remarks>
    /// The IEnumerable&lt;bool&gt; returned will be 
    /// sizeof(bool)*IEnumerable&lt;bool&gt;.Count() bytes rather than bits, 
    /// as BitArray stores it's elements in bits, not bytes.
    /// </remarks>
    public static IEnumerable<bool>
    GetEnumerator( this BitArray bitArrayToEnumerate ) {
      Contract.Requires(bitArrayToEnumerate != default(BitArray));

      foreach (bool bit in bitArrayToEnumerate) {
        yield return bit;
      }
    }
  }
}
